package com.zhika.zishi.fragments;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.zhika.zishi.R;
import com.zhika.zishi.activity.LetterChatActivity;
import com.zhika.zishi.adapter.ItemInformAdapter;
import com.zhika.zishi.adapter.ItemLetterAdapter;
import com.zhika.zishi.beans.ItemLetterBean;

import java.util.ArrayList;

/**
 * Created by shi-02 on 2015/4/19.
 * 私信和通知的Fragment
 */
public class LetterInformFragment extends Fragment {

    private View view;

    private ListView firstList;

    private ListView secondList;

    private ItemLetterAdapter userAdapter;

    private ItemLetterAdapter systemAdapter;

    private ItemInformAdapter informAdapter;

    private Context context;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.letter_inform_fragment_layout,container,false);
        initView();
        return view;
    }

    private void initView(){
        context = getActivity();

        firstList = (ListView) view.findViewById(R.id.letter_inform_fragment_first_list_view);
        secondList = (ListView) view.findViewById(R.id.letter_inform_fragment_second_list_view);

        Bundle bundle = getArguments();
        if (bundle!=null){
            String type = bundle.getString("letter_inform");
            if (type.equals("letter")){

                ArrayList<ItemLetterBean> userLetterList = (ArrayList<ItemLetterBean>) bundle.getSerializable("userLetter");
                userAdapter = new ItemLetterAdapter(context,userLetterList);
                firstList.setAdapter(userAdapter);
                firstList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        Intent intent = new Intent(context, LetterChatActivity.class);
                        context.startActivity(intent);
                    }
                });

                ArrayList<ItemLetterBean> systemLetterList = (ArrayList<ItemLetterBean>) bundle.getSerializable("systemLetter");
                systemAdapter = new ItemLetterAdapter(context,systemLetterList);
                secondList.setAdapter(systemAdapter);

            }else {
                secondList.setVisibility(View.GONE);
                ArrayList<String> informList = bundle.getStringArrayList("informlist");
                informAdapter = new ItemInformAdapter(context,R.layout.item_of_inform_fragment,informList);
                firstList.setAdapter(informAdapter);
            }
        }

    }
}
